package cn.saas.wanandroiddemo.base;

import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import cn.saas.wanandroiddemo.R;
import cn.saas.wanandroiddemo.databinding.ActivitySplashBinding;

/**
 * @author : admin
 * @Title :
 * @date : 2022/3/10 17:37
 */
public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(attachLayoutRes());
        if (useEventBus()) {
//            EventBus
        }
        initData();
        initTipView();
        initView();
        start();
        initListener();
    }

    /**
     * 布局文件id
     *
     * @return
     */
    protected abstract int attachLayoutRes();

    protected abstract void initListener();

    protected abstract void start();

    protected void initTipView() {
        View mTipVIew = LayoutInflater.from(this).inflate(R.layout.layout_network_tip, null);
        WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT
                , WindowManager.LayoutParams.WRAP_CONTENT
                , WindowManager.LayoutParams.TYPE_APPLICATION
                , (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
                , PixelFormat.TRANSLUCENT);
        lp.gravity = Gravity.TOP;
        lp.x = 0;
        lp.y = 0;
        lp.windowAnimations = R.style.anim_float_view;
    }

    ;

    /**
     * 初始化视图
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    protected boolean useEventBus() {
        return true;
    }


}
